home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / doom / suckmods.zip / SUCKMODS.ZIP / suck05 / src / id.qc < prev    next >
Text File  |  1997-05-09  |  3KB  |  106 lines

  1. // Identify the player you are pointed towards
  2. // By Suck (Nat Friedman)
  3. // This code falls under the GNU public license, and cannot be 
  4. // redistributed without my name attached.
  5.  
  6. // This is called with the player who wants to know whose in front
  7. // of him as "self."  I call it with an impulse in weapons.qc 
  8. entity(float disp) identify_player =
  9. {
  10.     // e is a temp entity; guy is our current best guess
  11.     // as to at whom the player is pointing
  12.     local entity e, guy;
  13.  
  14.     // The best "closeness" heuristic so far.
  15.     local float closeness = -1;
  16.  
  17.     // Temp vars.
  18.     local vector diff, point;
  19.     local float currclose;
  20.     local string s1, s2, s3;
  21.  
  22.     // Walk the list of players...
  23.     e=find(world, classname, "player");
  24.     while (e!=world)
  25.     {
  26.         // Get a vector pointing from the viewer to the current
  27.         // player under consideration
  28.         diff=e.origin - self.origin;
  29.  
  30.         // Normalize it since we only care where he's pointing,
  31.         // not how far away the guy is.
  32.         diff=normalize(diff);
  33.  
  34.         // Normalize self.angles so we can do a length-independent
  35.         // consideration
  36.         point=normalize(self.angles);
  37.  
  38.         // Find the different between the current player's angle
  39.         // and the viewer's vision angle
  40.         diff=diff - point;
  41.  
  42.         // The length is going to be our definition of closeness
  43.         currclose=vlen(diff);
  44.                 traceline(self.origin, e.origin, FALSE, self);
  45.                 if (trace_ent == e)
  46.                 {
  47.             if (closeness == -1)
  48.             {
  49.                 closeness = currclose;
  50.                 guy = e;
  51.             }
  52.             else if (currclose < closeness)
  53.             {
  54.                 closeness = currclose;
  55.                 guy = e;
  56.             }
  57.         }
  58.         e=find(e, classname, "player");
  59.     }
  60.  
  61.     // Now we display.
  62.     if (disp==0)
  63.         return guy;
  64.     self.status_time=time+1.75;
  65.     if (guy == world)
  66.     {
  67.         centerprint(self, "You're not looking at anyone!\n");
  68.         return world;
  69.     }
  70.     
  71.     if (guy.team == self.team)
  72.     {
  73.         if (guy.weapon == IT_AXE)
  74.             s1="Axe, ";
  75.         else if (guy.weapon == IT_HOOK)
  76.             s1="Hook, ";
  77.         else if (guy.weapon == IT_SHOTGUN)
  78.             s1="Shot, ";
  79.         else if (guy.weapon == IT_SUPER_SHOTGUN)
  80.             s1="DblBrl, ";
  81.         else if (guy.weapon == IT_NAILGUN)
  82.             s1="Nailgun,";
  83.         else if (guy.weapon == IT_SUPER_NAILGUN)
  84.             s1="S.Nailgun, ";
  85.         else if (guy.weapon == IT_GRENADE_LAUNCHER)
  86.             s1="Grenade, ";
  87.         else if (guy.weapon == IT_ROCKET_LAUNCHER)
  88.             s1="Rocket, ";
  89.         else if (guy.weapon == IT_LIGHTNING)
  90.             s1="TBolt, ";
  91.  
  92.         s2=ftos(guy.health);
  93.         if (guy.items&IT_ARMOR1)
  94.             s3="Green, ";
  95.         else if (guy.items&IT_ARMOR2)
  96.             s3="Yellow, ";
  97.         else if (guy.items&IT_ARMOR3)
  98.             s3="Red, ";
  99.         else s3="No Armor";
  100.         centerprint7(self, guy.netname, ": ", s1, s3, "Health: ", s2, "\n");
  101.     }
  102.     else
  103.         centerprint3(self, "You are looking at ", guy.netname, "\n");
  104.  
  105.     return guy;
  106. };